﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;

namespace EIA.SLClient.ProjectManage.Basic
{
	public partial class ProjectInfoControl : UserControl
	{
		public ProjectInfoControl()
		{
			// 为初始化变量所必需
			InitializeComponent();
		}

        #region ProjectBasic (DependencyProperty)

        /// <summary>
        /// 该依赖属性的描述
        /// </summary>
        public EIA.PM.Model.TProjectBasic ProjectBasic
        {
            get { return (EIA.PM.Model.TProjectBasic)GetValue(ProjectBasicProperty); }
            set { SetValue(ProjectBasicProperty, value); }
        }
        public static readonly DependencyProperty ProjectBasicProperty =
            DependencyProperty.Register("ProjectBasic", typeof(EIA.PM.Model.TProjectBasic), typeof(ProjectInfoControl),
            new PropertyMetadata(null, new PropertyChangedCallback(OnProjectBasicChanged)));

        private static void OnProjectBasicChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            // 获取自身的引用
            ProjectInfoControl source = (ProjectInfoControl)sender;

            // 处理逻辑
            EIA.PM.Model.TProjectBasic newValue = (EIA.PM.Model.TProjectBasic)args.NewValue;

            try
            {
                (source.LayoutRoot.DataContext as ProjectInfoControlViewModel).Model = newValue;
            }
            catch
            {
            }
        }

        #endregion

        #region IsEditing (DependencyProperty)

        /// <summary>
        /// 该依赖属性的描述
        /// </summary>
        public bool IsEditing
        {
            get { return (bool)GetValue(IsEditingProperty); }
            set { SetValue(IsEditingProperty, value); }
        }
        public static readonly DependencyProperty IsEditingProperty =
            DependencyProperty.Register("IsEditing", typeof(bool), typeof(ProjectInfoControl),
            new PropertyMetadata(false, new PropertyChangedCallback(OnIsEditingChanged)));

        private static void OnIsEditingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            // 获取自身的引用
            ProjectInfoControl source = (ProjectInfoControl)sender;

            // 处理逻辑
            bool newValue = (bool)args.NewValue;
            try
            {
                (source.LayoutRoot.DataContext as ProjectInfoControlViewModel).IsEditing = newValue;
            }
            catch
            {
            }
        }

        #endregion
	}
}